<template>
  <div>
    <dialog-edit :visible.sync="dialogVisible" :title="$attrs.Title||'转计划'" ref="userManageEdit" width="400"
                 height="200" @save="save" :saveLoading="saveLoading">
      <template slot="body">
        <el-form ref="form" :model="preFormData" label-width="80px" :rules="rules">
          <el-form-item label="开始日期" prop="Started">
            <!--            <el-input v-model="preFormData.name"></el-input>-->
            <el-date-picker v-model="preFormData.Started" type="date" value-format="timestamp" placeholder="请选择开始日期"></el-date-picker>
          </el-form-item>
          <el-form-item label="结束日期" prop="Ended">
            <!--            <el-input v-model="preFormData.name"></el-input>-->
            <el-date-picker v-model="preFormData.Ended" type="date" value-format="timestamp" placeholder="请选择结束日期"></el-date-picker>
          </el-form-item>
        </el-form>
      </template>
    </dialog-edit>
  </div>
</template>

<script>
import dialogEdit from '@/components/element/dialogEdit'
import dymForm from '@/components/element/dymForm'
import testDialog from '@/page/ProjectManage/modules/proTest/testDialog'
import projectNeedSwimlane from "@/api/organizationApi/projectNeedSwimlane";
import projectPlanApi from "@/api/projectPlanApi";
import projectNeedApi from "@/api/organizationApi/projectNeedApi";

export default {
  name: "PlanDialog",
  inject: {
    initData: {
      default: null
    }
  },
  components: {
    dialogEdit,
    dymForm,
    testDialog
  },
  props: {
    visible: {
      type: Boolean,
      default() {
        return false;
      }
    },
    formData: {
      type: Object,
      default() {
        return {};
      }
    }
  },
  data () {
    return {
      options: [],
      saveLoading: false,
      testDialogVisible: false,
      preFormData: {
        name: ''
      },
      rules: {
        Started: {required: true, message: '开始时间必填', trigger: 'change'},
        Ended: {required: true, message: '结束时间必填', trigger: 'change'},
      }
    }
  },
  computed: {
    dialogVisible: {
      get: function () {
        return this.visible
      },
      set: function (value) {
        this.$emit('update:visible', value)
      }
    }
  },
  methods: {
    save () {
      this.$refs.form.validate().then(res => {
        let a = Object.assign(this.formData, this.preFormData)
        this.saveLoading = true
        projectNeedSwimlane.toPlanById(a).then(res => {
          if (res) {
            this.dialogVisible = false
            this.$message({ type: res.code === 1 ? 'success' : 'warning', message: res.message })
            this.isClick = false
            this.initData.getNeedList()
          }
        }).finally(() => {
          this.saveLoading = false
        })
      }).catch(res => {
        this.warning('检查标红位置')
      })
    }
    // 通过项目获取计划列表
    // getPlanListByProject () {
    //   let a = {
    //     id: this.formData.Projectid,
    //     p: 1,
    //     pageoffset: 10000
    //
    //   }
    //   projectPlanApi.getPage({a}).then(res => {
    //     if (res && res.Needs) {
    //       this.options = res.Needs
    //     }
    //   })
    // }
  },
  watch: {
    // dialogVisible: {
    //   handler (n, o) {
    //     if (n) {
    //       this.getPlanListByProject()
    //     }
    //   }
    // }
  }
}
</script>

<style scoped>
.dymForm >>> .el-date-editor {
  width: 100%;
}
</style>